import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/src/size_extension.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:meiyunapp/generated/assets.dart';
import 'package:get/get.dart';
import 'package:meiyunapp/page/login/login_collect.dart';
import 'package:meiyunapp/router/routers_pages.dart';
import 'package:meiyunapp/style/k_color.dart';

class LoginPage extends StatelessWidget {
  LoginPage({Key? key}) : super(key: key);

  var mLoginCollect = Get.find<LoginCollect>();

  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion(
      value: SystemUiOverlayStyle.dark,
      child: Scaffold(
        resizeToAvoidBottomInset: false,
        body: GestureDetector(
          onTap: () {
            FocusScope.of(context).requestFocus(FocusNode());
          },
          child: Container(
            margin: const EdgeInsets.only(top: 122),
            color: Colors.white,
            child: Column(
              children: [
                SizedBox(
                  height: 55,
                  width: 142,
                  child: SvgPicture.asset(Assets.svgLogoZlw),
                ),
                const SizedBox(
                  height: 30,
                ),
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 40),
                  child: TextField(
                    controller: mLoginCollect.mPhoneCollect,
                    maxLines: 1,
                    keyboardType: TextInputType.number,
                    style: const TextStyle(fontSize: 14, color: Colors.black87),
                    inputFormatters: <TextInputFormatter>[
                      LengthLimitingTextInputFormatter(12)
                    ],
                    decoration: InputDecoration(
                      hintText: "请输入手机号码",
                      hintStyle: Theme.of(context)
                          .textTheme
                          .headline6!
                          .copyWith(color: KColor.ColorAAAAAA),
                      isCollapsed: true,
                      contentPadding: const EdgeInsets.symmetric(
                          vertical: 15, horizontal: 12),
                      border: OutlineInputBorder(
                          gapPadding: 0,
                          borderRadius: BorderRadius.circular(20),
                          borderSide: const BorderSide(
                              width: 0.1, color: Colors.black26)),
                    ),
                  ),
                ),
                const SizedBox(
                  height: 15,
                ),
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 40),
                  child: Stack(
                    children: [
                      TextField(
                        maxLines: 1,
                        keyboardType: TextInputType.number,
                        inputFormatters: <TextInputFormatter>[
                          LengthLimitingTextInputFormatter(6)
                        ],
                        controller: mLoginCollect.mCodeCollect,
                        style: const TextStyle(
                            fontSize: 14, color: Colors.black87),
                        decoration: InputDecoration(
                          hintText: "请输入验证码",
                          hintStyle: Theme.of(context)
                              .textTheme
                              .headline6!
                              .copyWith(color: KColor.ColorAAAAAA),
                          isCollapsed: true,
                          contentPadding: const EdgeInsets.symmetric(
                              vertical: 15, horizontal: 12),
                          border: OutlineInputBorder(
                              gapPadding: 0,
                              borderRadius: BorderRadius.circular(20),
                              borderSide: const BorderSide(
                                  width: 0.1, color: Colors.black26)),
                        ),
                      ),
                      Positioned(
                          right: 20,
                          top: 15,
                          child: GestureDetector(
                            onTap: () {
                              mLoginCollect.sendMessage(
                                  mLoginCollect.mPhoneCollect.text.trim());
                            },
                            child: Obx(() => Text(
                                  "${mLoginCollect.codeStr}",
                                  style: const TextStyle(
                                      color: KColor.Color0C5BE5, fontSize: 16),
                                )),
                          ))
                    ],
                  ),
                ),
                const SizedBox(
                  height: 30,
                ),
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 40),
                  child: ElevatedButton(
                    onPressed: () {
                      /*mLoginCollect.login(
                          mPhoneCollect.text.trim(), mCodeCollect.text.trim());*/
                      Get.offNamed(RouterPath.home_path,
                          arguments: {"name": "test"});
                    },
                    child: Container(
                        alignment: Alignment.center,
                        width: double.infinity,
                        height: 45,
                        child: const Text("登录")),
                  ),
                ),
                const SizedBox(
                  height: 10,
                ),
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: 5.w),
                  child: Row(
                    children: [
                      Obx(
                        () => Container(
                          padding: EdgeInsets.zero,
                          width: 30.0,
                          child: IconButton(
                              onPressed: () {
                                mLoginCollect
                                    .setCheck(!mLoginCollect.isCheck.value);
                              },
                              icon: Icon(
                                mLoginCollect.isCheck.value
                                    ? Icons.check_circle_outline
                                    : Icons.check_circle,
                                color: mLoginCollect.isCheck.value
                                    ? Colors.black26
                                    : KColor.Color0C5BE5,
                                size: 20,
                              )),
                        ),
                      ),
                      ExcludeSemantics(
                        excluding: true,
                        child: RichText(
                          text: TextSpan(
                            text: '我已理解并同意 ',
                            style: Theme.of(context)
                                .textTheme
                                .headline6!
                                .copyWith(fontSize: 12),
                            children: [
                              TextSpan(
                                  text: "《猪灵网使用协议》",
                                  style: TextStyle(
                                      color: KColor.Color0C5BE5,
                                      fontSize: 12.sp),
                                  recognizer: TapGestureRecognizer()
                                    ..onTap = () {
                                      Get.snackbar("提示", "点击了猪灵网使用协议");
                                    }),
                              const TextSpan(
                                text: "和",
                              ),
                              TextSpan(
                                text: "《客户经理授权协议》",
                                style: TextStyle(
                                    color: KColor.Color0C5BE5, fontSize: 12.sp),
                                recognizer: TapGestureRecognizer()
                                  ..onTap = () {
                                    Get.snackbar("提示", "点击了客户经理授权协议");
                                  },
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                const SizedBox(
                  height: 60,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Container(
                      width: 80.w,
                      height: 0.5.h,
                      color: Colors.black26,
                    ),
                    const Text(
                      "其它登录方式",
                      style: TextStyle(color: Colors.black26),
                    ),
                    Container(
                      width: 80.w,
                      height: 0.5.h,
                      color: Colors.black26,
                    ),
                  ],
                ),
                SizedBox(
                  height: 10.h,
                ),
                IconButton(
                  onPressed: () {},
                  icon: Icon(
                    FontAwesomeIcons.weixin,
                    size: 40.r,
                    color: KColor.Color0C5BE5,
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
